require("options.events")
local global = require("options.global")
-- Display related ----------
-- vim.cmd([[syntax off]])
vim.cmd([[syntax on]])
vim.o.number = true
vim.o.relativenumber = true

-- Do not source the default filetype.vim
vim.g.did_load_filetypes = 1

-- Setup sqlite3 path
vim.g.sqlite_clib_path = "C:\\ProgramData\\chocolatey\\lib\\SQLite\\tools\\sqlite3.dll"

-- Scheme related
vim.o.termguicolors = true
-- vim.o.background = "dark"
vim.cmd([[colorscheme catppuccin]])
vim.g.catppuccin_flavour = "mocha"
-- vim.cmd([[colorscheme rose-pine]])

vim.o.errorbells = true
vim.o.visualbell = true
vim.o.hidden = true
vim.o.fileformats = "unix,mac,dos"

vim.o.cursorline = true
vim.o.cursorcolumn = true

vim.o.list = true

vim.o.showbreak = "↳  "
vim.o.listchars = "tab: ..,nbsp:+,trail:·,extends:→,precedes:←"
-- vim.o.listchars = "tab:.ﴪ,nbsp:+,trail:·,extends:→,precedes:←"

vim.o.showtabline = 2

vim.o.linebreak = true
vim.o.wrap = true

vim.o.formatoptions = "1jcroql"

vim.o.textwidth = 80

-- pseudo-transparency
vim.o.pumblend = 10
vim.o.winblend = 10

-- Some sizes
vim.o.winwidth = 30
vim.o.winminwidth = 30
vim.o.pumheight = 15
vim.o.helpheight = 12
vim.o.previewheight = 12

vim.o.cmdheight = 2
vim.o.cmdwinheight = 5

-- Auto equal size of splits?
vim.o.equalalways = false

vim.o.laststatus = 2

-- Display special chars
vim.o.magic = true

vim.o.encoding = "utf-8"
vim.o.viewoptions = "folds,cursor,curdir,slash,unix"
vim.o.sessionoptions = "curdir,help,tabpages,winsize"

if global.is_mac then
	vim.g.clipboard = {
			name = "macOS-clipboard",
			copy = { ["+"] = "pbcopy", ["*"] = "pbcopy" },
			paste = { ["+"] = "pbpaste", ["*"] = "pbpaste" },
			cache_enabled = 0,
		}
	vim.g.python_host_prog = "/usr/bin/python"
	vim.g.python3_host_prog = "/usr/local/bin/python3"
else
	vim.o.clipboard = "unnamedplus"
end

vim.signcolumn = "yes"
conceallevel = 0
concealcursor = "niv"

-- Command related ----------

vim.o.wildmenu = true
vim.o.wildignore =
	".git,.hg,.svn,*.pyc,*.o,*.out,*.jpg,*.jpeg,*.png,*.gif,*.zip,**/tmp/**,*.DS_Store,**/node_modules/**,**/bower_modules/**"

vim.o.swapfile = false

vim.o.undofile = true
vim.o.undodir = global.cache_dir .. "undo/"
history = 2000
shada = "!,'300,<50,@100,s10,h"
backupskip = "/tmp/*,$TMPDIR/*,$TMP/*,*/shm/*,/private/var/*,.vault.vim"

-- Hight light search
vim.o.hlsearch = true

-- Instance search
vim.o.incsearch = true
vim.o.showmatch = true
vim.o.smartcase = true
vim.o.wrapscan = true

-- Tab related ----------
-- vim.o.expandtab = true
vim.o.tabstop = 4
vim.o.softtabstop = 4
vim.o.shiftwidth = 4
vim.o.smartindent = true
vim.o.shiftround = true

vim.o.breakindentopt = "shift:2,min:20"

-- Coding related ----------
-- Code folding
vim.o.foldenable = true
-- Auto close when move out
vim.o.foldclose = "all"
-- All no fold closed when starting
vim.o.foldlevelstart = 99
-- Available: manual, indent, expr, marker, syntax, diff
-- vim.o.foldmethod = "syntax"

-- vim.api.nvim_create_autocmd("BufRead,*.py","set foldmethod=indent")

vim.o.synmaxcol = 2500

vim.o.scrolloff = 4
vim.o.sidescrolloff = 5

vim.o.breakat = [[\ \ ;:,!?]]

vim.o.autoread = true
vim.o.autowrite = true

-- Move cursur to the start after jump
vim.o.startofline = false

vim.o.whichwrap = "<,>,~"

vim.o.splitbelow = true
vim.o.splitright = true

vim.o.backspace = "indent,eol,start"

vim.o.updatetime = 100
vim.o.redrawtime = 1500

-- vim.opt.spell = true
-- vim.opt.spelllang = { 'en_gb' }
vim.opt.guifont = { "JetBrainsMono NF", "h13" }

-- Unlikely usefull ==========

vim.o.jumpoptions = "stack"

vim.o.switchbuf = "useopen"

vim.o.diffopt = "filler,iwhite,internal,algorithm:patience"

-- Quite confusing ===========
vim.o.complete = ".,w,b,k"
vim.o.completeopt = "menuone,noselect,menu"

vim.o.inccommand = "nosplit"
vim.o.grepformat = "%f:%l:%c:%m"
vim.o.grepprg = "rg --hidden --vimgrep --smart-case --"

vim.o.shortmess = "aoOTIcF"

-- Global variables ==========
vim.g.mapleader = " "

-- For undo tree ============
if vim.fn.has("persistent_undo") then
	target_path = vim.fn.expand("~/.undodir")

	-- create the directory and any parent directories
	-- if the location does not exist.
	if not vim.fn.isdirectory(target_path) then
		-- call mkdir(target_path, "p", 0700)
		os.execute("mkdir " .. "-p " .. "-m=0700 " .. target_path)
	end

	-- let &undodir=target_path
	vim.g.undodir = target_path
end
